package com.gx.smart.building.ui.repair.fragment

import android.content.Intent
import android.view.View
import android.view.ViewGroup
import androidx.navigation.fragment.findNavController
import com.gx.smart.base.BaseMVVMFragmentV2
import com.gx.smart.building.R
import com.gx.smart.building.databinding.FragmentRepairResultBinding
import com.gx.smart.building.ui.repair.RepairActivity
import com.gx.smart.building.ui.repair.viewmodel.RepairViewModel

class RepairResultFragment : BaseMVVMFragmentV2<RepairViewModel>() {

    private lateinit var viewBinding: FragmentRepairResultBinding
    override fun onBindLayout(): Int = R.layout.fragment_repair_result

    override fun getToolbarTitle(): String {
        return requireArguments().getString("type").let {
            when (it) {
                "receive" -> "工单接收"
                "resume" -> "工单解挂"
                "back" -> "工单退回"
                "process" -> "工单完成"
                "suspend" -> "工单挂起"
                "transform" -> "工单转派"
                else -> "工单"
            }
        }
    }

    override fun onBindViewModel(): Class<RepairViewModel> = RepairViewModel::class.java

    override fun initContentView(root: ViewGroup) {
        viewBinding = FragmentRepairResultBinding.inflate(layoutInflater, root, true)
    }

    override fun initData() {
        requireArguments().getString("type").let {
            when (it) {
                "receive" -> viewBinding.desc.text = "工单已接收！"
                "resume" -> viewBinding.desc.text = "工单已解挂！"
                "back" -> {
                    viewBinding.desc.text = "工单已回退！"
                    viewBinding.detail.visibility = View.GONE
                }
                "process" -> viewBinding.desc.text = "工单已完成！！"
                "suspend" -> viewBinding.desc.text = "挂起申请提交，等待审批！"
                "transform" -> {
                    viewBinding.desc.text = "工单已转派！"
                    viewBinding.detail.visibility = View.GONE
                }
            }

        }
        viewBinding.detail.setOnClickListener {
            findNavController().navigateUp()
        }
        viewBinding.list.setOnClickListener {
            val intent = Intent(requireActivity(), RepairActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
            startActivity(intent)
            requireActivity().finish()
        }
    }
}